#import "HomeView.h"
#import "MainView.h"

@implementation HomeView 

@synthesize textFieldMins;

enteredMinutes = "";
mainValue = 0;

- (IBAction)save {
	
	
	[self removeFromSuperview];
}

- (IBAction)startTimer {
	paused = NO;
	if(timer != nil) {
		[timer invalidate];
	}
	timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/1.0) target:self selector:@selector (updateLabel) userInfo:nil repeats:YES];
	
}

- (void)updateLabel {
	if (paused == YES) {
		return;
	}
	if (paused == NO) {
		mainValue -= 1;
		countdownLabel.text = [NSString stringWithFormat:@"%d", mainValue];
	}
}

- (IBAction)togglePause {
	if (paused == NO) {
		paused = YES;
	}
}

- (IBAction)resetTimer {
	[timer invalidate];
	timer = nil;
	paused = YES;
	mainValue = 0;
	countdownLabel.text = [NSString stringWithFormat:@"%d", mainValue];
}



- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
    if (theTextField == textFieldMins) {
		double myDouble = [textFieldMins.text doubleValue];
		mainValue = (int)(myDouble);
        [textFieldMins resignFirstResponder];
    }
    return YES;
}
 



@end
